
Page({
  data: {
    navItems: [  
      { id: 1, label: '专业急救' },  
      { id: 2, label: '医学知识' },  
      { id: 3, label: '运动健身' },  
      { id: 4, label: '养老保健' },  
    ],  
        list: [
      {
        name: '王医生',
        num: '10',
        title: '关键时刻能“救命”！常用急救知识合集',
        url: '../../../img/头痛.png',
        avatar: 'https://img1.baidu.com/it/u=610726533,1686239110&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=750',
        nav:'../../news/newsdetail/newsdetail'
      },
      {
        name: '苏苏洛',
        num: '8',
        title: '日常急救知识（推荐收藏～）',
        url: '../../../img/日常.png',
        avatar: 'https://img0.baidu.com/it/u=1555018837,2431012166&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500',
        nav:'../../news/kyo/kyo'
      },
      {
        name: '李主任',
        num: '12',
        title: '发生了心肌梗死怎么办？来看看这个',
        url: '../../../img/心肌梗死.png',
        avatar: 'https://img2.baidu.com/it/u=2656232546,4221523240&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=777',
        nav:'../../news/newsdetail/newsdetail'
      },
      {
        name: '妙手回春',
        num: '99+',
        title: '烈日下的紧急救援，他们是真正的天使',
        url: '../../../img/烈日.png',
        avatar: 'https://img1.baidu.com/it/u=2602506082,2229028687&fm=253&fmt=auto&app=138&f=JPEG?w=796&h=500',
        nav:'../../news/kyo/kyo'
      },
      {
        name: '阿伟',
        num: '66',
        title: '上心肺复苏机到放弃的界点在哪里！',
        url: '../../../img/心肺.png',
        avatar: 'https://img1.baidu.com/it/u=3462460603,3220043498&fm=253&fmt=auto&app=120&f=JPEG?w=690&h=458',
        nav:'../../news/newsdetail/newsdetail'
      },
      {
        name: '七月',
        num: '8',
        title: '速看！急救基础知识重点总结',
        url: '../../../img/守护.png',
        avatar: 'https://img0.baidu.com/it/u=3184989322,3773788620&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=667',
        nav:'../../news/kyo/kyo'
      },
    ],
    currentTab: 0,
    sleft: 0,
  },
  navigateToCard: function() {  
    console.log("Button clicked!");
    wx.navigateTo({  
      url: `../../news/newsdetail/newsdetail`,
      complete: function (res) {
        console.log(res); // 输出跳转结果
      } 
    }); 
  },
  handleTabChange(e) {
    let { currnet } = e.currentTarget.dataset;
    if (this.data.currentTab == currnet || currnet == undefined) return;
    this.setData({
      currentTab: currnet
    })
  },
  //处理swiper 滑动事件
  handleSwiperChange(e) {
    this.setData({
      currentTab: e.detail.current
    });
    // 在处理swiper的滑动事件中，处理sleft的值
    this.getScrollLeft()
  },
  // 处理sleft的值
  getScrollLeft() {
    const query = wx.createSelectorQuery();
    query.selectAll(".item").boundingClientRect();
    query.exec(res => {
      let num = 0;
      for (let i = 0; i < this.data.currentTab; i++) {
        num += res[0][i].width;
      }
      this.setData({
        sleft: Math.ceil(num)
      })
    })
  }

})